$(function(){
	
	// 项目区域数据请求
	$.ajax({
		type: "GET",
        url: host +"volunteerProject/getListofArea",
        dataType: "json",
        success: function(data){
			$.each(data,function(index,item){
				$('#regionbox').append('<span id="'+item.id+'">'+item.areaName+'</span>')
			})
			
		}
 
	})
	// 服务类型数据请求
	$.ajax({
		type: "GET",
		url: host +"volunteerTeam/getteamServiceType",
		dataType: "json",
		success: function(data){
			$.each(data,function(index,item){
				$('#categorybox').append('<span id="'+item.id+'">'+item.serviceName+'</span>')
			})
			
		}
	
	})
	// 团体类型数据请求
	$.ajax({
		type: "GET",
		url: host +"volunteerTeam/getTeamType",
		dataType: "json",
		success: function(data){
			$.each(data,function(index,item){
				$('#typebox').append('<span id="'+item.id+'">'+item.teamType+'</span>')
			})
			
		}
	
	})
	
	// 点击搜索传参  查询数据
	$('.searchbtn').click(function(){
		$.ajax({
			type: "GET",
			url: host +"volunteerTeam/getListOfTeamSign",
			data:{
				startDate:$('.teamStart').val(),
				endDate:$('.teamEnd').val(),
				id:$('.teamId').val(),
				title:$('.teamTitle').val()
				
			},
			dataType: "json",
			success: function(data){
				
			}
		})
	})
	
	// 获取志愿团队列表
	var $oResultBox = $('.teambox');
	//var books = data.books;
	
	$.ajax({
		type:"get",
		url:host +"volunteerTeam/getVolunteerList",
		async:true,
		dataType:"json",
		success:function(data){
			var books = data.result;
				
			console.log(books)
				
			$('#paging').paging({
				nowPage: 1,
				allPages: Math.ceil(data.total / 8),
				displayPage: 6,
				callBack: function (now) {
				var currentPages = now * 8 < books.length ? 8 : books.length - (now - 1) * 8;
			
				// $oResultBox.html('');
			
				for (var i = 0; i < currentPages; i++) {
					var num = (now - 1) * 8 + i;
					var showimg = '';
					if(books[num].url != null){
						showimg = 'http://101.201.113.151:9000'+books[num].url.split('ROOT')[1] ;
					}
					var createDate = books[num].createDate.substr(0, 10);
					console.log(showimg)
					var _html = '<div class="box">'+
					                '<input type="hidden" value="'+books[num].id+'" class="userId">'+
									'<div class="img"><img src="'+showimg+'"></></div>'+
									'<div class="t_title">'+books[num].title+'</div>'+
									'<div class="num">团体人数：<span>'+books[num].teamNum+'</span></div>'+
									'<div class="time">成立日期：<span>'+createDate+'</span></div>'+
									'<div class="address">团体地址：<span>'+books[num].teamAddress+'</span></div>'+
						        '</div>';
					$oResultBox.append(_html);
					
					// 点击进入志愿团体详情页面
					$('.box').click(function(){
						var userId = $(this).children('.userId').val();
						window.location.href="details_team.html?id="+userId;
					});
					
					
				}
				},
					
					
			}); 
	
		},
			
	});
	
	
	
	
	
	
	
})